package com.nd.controller.wx;

import com.nd.pojo.bean.Admin;
import com.nd.pojo.bean.Region;
import com.nd.pojo.bean.Storage;
import com.nd.pojo.bean.User;
import com.nd.pojo.bo.wx.AddressAddBO;
import com.nd.pojo.bo.wx.IdBO;
import com.nd.pojo.vo.wx.AddressVO;
import com.nd.pojo.bo.wx.FeebackBo;
import com.nd.pojo.vo.wx.BaseRespWXVo;
import com.nd.service.StorageService;
import com.nd.service.wx.AddressService;
import com.nd.service.wx.FeebackService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

/**
 * @program: project2mall
 * @description: 图片上传控制类
 * @author: shit_code_builder
 * @create: 2021-06-07 22:01
 **/
@RestController
@RequestMapping("wx")
public class StorageController {

    @Autowired
    StorageService storageService;

    @Autowired
    FeebackService feebackService;

    @Autowired
    AddressService addressService;

    @RequestMapping("storage/upload")
    public BaseRespWXVo upload(@RequestParam("file") MultipartFile myFile) throws Exception {
        Storage uploads = storageService.uploadFiles(myFile);
        if(uploads == null) return BaseRespWXVo.fail();
        return BaseRespWXVo.ok(uploads);
}
    @PostMapping("/feedback/submit")
    public BaseRespWXVo feedback(@RequestBody FeebackBo bo){

        BaseRespWXVo baseRespWXVo = feebackService.submitFeedback(bo);

        return  baseRespWXVo;
    }

    @GetMapping("/address/list")
    public BaseRespWXVo<List<AddressVO>> addressList(){

        BaseRespWXVo<List<AddressVO>> baseRespWXVo= addressService.addressList();
    return baseRespWXVo;
    }

    @GetMapping("/region/list")
    public  BaseRespWXVo<List<Region>> selectRegin(Integer pid){

        BaseRespWXVo<List<Region>> baseRespWXVo= addressService.selectRegin(pid);

        return baseRespWXVo;
    }

    @PostMapping("/address/save")
    public  BaseRespWXVo<Integer> saveRegion (@RequestBody AddressAddBO bo){

        BaseRespWXVo<Integer> baseRespWXVo= null ;

            baseRespWXVo = addressService.addAddress(bo);

        return baseRespWXVo;
    }

    @PostMapping("/address/delete")
    public  BaseRespWXVo deleteRegion ( @RequestBody IdBO id){

        BaseRespWXVo baseRespWXVo= addressService.delAddress(id.getId());
        return baseRespWXVo;
    }

}
